let addUser = document.querySelector("#add-user");
let double1 = document.querySelector("#double")
let main = document.querySelector("#main");
let millionaire = document.querySelector("#show-millionaire")
let sortSpan = document.querySelector("#sort")
let nav = document.querySelector("nav")
let calculate = document.querySelector("#calculate")
let num = 0;
var nba = [{
    name: "杜兰特",
    AnnualSalary: "$408678.00"
}, {
    name: "纳什",
    AnnualSalary: "$560867.00"
}, {
    name: "阿尔德里奇",
    AnnualSalary: "$988678.00"
}, {
    name: "格里芬",
    AnnualSalary: "$908678.00"
}, {
    name: "哈登",
    AnnualSalary: "$768678.00"
}, {
    name: "欧文",
    AnnualSalary: "$658678.00"
}, {
    name: "米尔萨普",
    AnnualSalary: "$728678.00"
}, {
    name: "哈里斯",
    AnnualSalary: "$358678.00"
}];

//添加账户
addUser.addEventListener("click", function() {
    if (num < nba.length) {
        let h2 = document.createElement("h2");
        h2.innerHTML = "<strong>" + (num + 1 + ":") + nba[num].name + "</strong>" + "<span class='span1'>" + nba[num].AnnualSalary + "</span>";
        main.appendChild(h2);
        h2.style.height = "40px"
        num++;
    }
})


//资金翻倍
double1.addEventListener("click", function() {
    let spanList = document.querySelectorAll(".span1")
    spanList.forEach((item, index) => {
        // item.innerHTML = "$" + item.innerHTML.slice(1) * 2;
        if (item.innerHTML.slice(1) < 10000000) {
            item.innerHTML = "$" + item.innerHTML.slice(1) * 2;
        } else {
            item.innerHTML = "$" + 20000000;
        }
    })
})

//查询百万富翁
millionaire.addEventListener("click", function() {
    let spanList = document.querySelectorAll(".span1")
    spanList.forEach((item, index) => {
        // item = item.innerHTML.slice(1);
        // console.log(+item.innerHTML.slice(1));
        if (+item.innerHTML.slice(1) < 1000000) {
            item.parentElement.remove();
        }
    })

})


//财富榜
sortSpan.addEventListener("click", function() {
    // let hhh = document.querySelectorAll("main h2:not(:first-child)")
    // let ab = [];
    // // console.log(spanList.length);
    // hhh.forEach((item, index) => {
    //     item = +item.children[1].innerHTML.slice(1)
    //     ab.push(item);
    //     ab.sort(function(a, b) {
    //             return b - a;
    //         })
    //         // item.children[1]
    //         // console.log(+item.children[1].innerHTML.slice(1));

    // })

    let list = document.querySelectorAll(".span1")
    for (i = 0; i < list.length; i++) {
        if (list[0].innerHTML.slice(1) * 1 > list[i].innerHTML.slice(1)) {

        }
        // console.log(list[i].innerHTML.slice(1) * 1);
    }

})


//计算总额
calculate.addEventListener("click", function() {
    let spanList = document.querySelectorAll(".span1");
    let a = 0;
    for (i = 0; i < spanList.length; i++) {
        a += spanList[i].innerHTML.slice(1) * 1;
    }
    let h2 = document.createElement("h2");
    h2.innerHTML = "<strong>" + "总额:" + "</strong>" + "<span class='span1'>" + "$" + a + "</span>";
    main.appendChild(h2);
})


//导航栏
let toggle = document.getElementById("toggle");
let container = document.querySelector(".container")
let flag = false;
toggle.addEventListener("click", function() {
    if (nav.style.transform = "translate(0)") {
        flag = true;
        nav.style.width = "120px"
        toggle.style.left = "150px"
    } else {
        flag = false;
    }
})